<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation />

      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="bisZhsqSnryXm" label="姓名" />
        <el-table-column prop="bisZhsqSnrySfz" label="身份证" />
        <el-table-column prop="bisZhsqJhrxm" label="监护人姓名" />
        <el-table-column prop="bisZhsqJhrdh" label="监护人电话" />
        <el-table-column prop="bisOrderHlrq" label="护理日期" />
        <el-table-column prop="bisOrderHlyName" label="护理人员" />
        <el-table-column prop="payJsFee" label="总费用" />
        <el-table-column prop="payJsCashAmt" label="自费金额" />
        <el-table-column prop="payJsFirstAmt" label="支付金额" />
        <el-table-column prop="payJsTradeTime" label="交易时间" />
        <el-table-column prop="payRefundStas" label="退费状态" />
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleClick(scope.row, '1')">退费</el-button>
            <el-button type="text" size="small" @click="handleClick(scope.row, '2')">取消医保结算</el-button>
            <el-button type="text" size="small" @click="handleClick(scope.row, '3')">退费加取消医保结算</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudFixedCosts from '@/api/business/fixedCosts'
import { queryAllHljgYmk } from '@/api/business/ymkdz'
import { refundPay } from '@/api/business/paid'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisFixedCostsId: null, bisFixedCostsJzid: null, bisFixedCostsZhid: null, bisFixedCostsYpbm: null, bisFixedCostsMc: null, bisFixedCostsDj: null, bisFixedCostsSl: null, bisFixedCostsZj: null, bisFixedCostsZxks: null, bisFixedCostsZxts: null, bisFixedCostsJx: null, bisFixedCostsJl: null, bisFixedCostsYf: null, bisFixedCostsYl: null, bisFixedCostsSypc: null, bisFixedCostsDw: null, bisFixedCostsGg: null, bisFixedCostsFwlx: null }
export default {
  name: 'Paid',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '固定费用', url: 'api/pay/refundList', idField: 'bisZhsqId', sort: '', crudMethod: { ...crudFixedCosts }})
  },
  data() {
    return {
      fixedCostsDialog: false,
      allHljgYmk: [],
      zhid: '',
      jzid: '',
      zxks: '',
      rules: {
        bisFixedCostsJx: [
          { required: true, message: '剂型不能为空', trigger: 'blur' }
        ],
        bisFixedCostsJl: [
          { required: true, message: '剂量不能为空', trigger: 'blur' }
        ],
        bisFixedCostsYf: [
          { required: true, message: '用法不能为空', trigger: 'blur' }
        ],
        bisFixedCostsYl: [
          { required: true, message: '用量不能为空', trigger: 'blur' }
        ],
        bisFixedCostsSypc: [
          { required: true, message: '使用频次不能为空', trigger: 'blur' }
        ],
        bisFixedCostsDw: [
          { required: true, message: '单位不能为空', trigger: 'blur' }
        ],
        bisFixedCostsGg: [
          { required: true, message: '规格不能为空', trigger: 'blur' }
        ],
        bisFixedCostsZxts: [
          { required: true, message: '执行天数不能为空', trigger: 'blur' }
        ],
        bisFixedCostsSl: [
          { required: true, message: '数量不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 初始化编辑时候的角色与岗位
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.queryAllHljgYmk()
    },
    // 初始化编辑时候的角色与岗位
    [CRUD.HOOK.beforeToAdd](crud, form) {
      this.queryAllHljgYmk()
    },
    fixedCostsCancel() {
      this.fixedCostsDialog = false
    },
    // 获取所有机构服务项目
    queryAllHljgYmk() {
      queryAllHljgYmk().then(res => {
        this.allHljgYmk = res
      }).catch(() => { })
    },
    // 获取选中的对象
    seletChange(val) {
      // 选中的数据和options进行匹配
      var obj = {}
      obj = this.allHljgYmk.find(function(i) {
        return i.bisYmkdzYbmc === val
      })
      const that = this
      // 在change中获取到整条对象数据
      console.log(obj)
      this.form.bisFixedCostsDj = obj.bisYmkdzDj
      this.form.bisFixedCostsYpbm = obj.bisYmkdzYbbm
      this.form.bisFixedCostsJx = obj.bisYmkdzJx
      this.form.bisFixedCostsJl = obj.bisYmkdzJl
      this.form.bisFixedCostsSypc = obj.bisYmkdzSypc
      this.form.bisFixedCostsYf = obj.bisYmkdzYf
      this.form.bisFixedCostsYl = obj.bisYmkdzYl
      this.form.bisFixedCostsZxts = obj.bisYmkdzZxts
      this.form.bisFixedCostsDw = obj.bisYmkdzDw
      this.form.bisFixedCostsGg = obj.bisYmkdzGg
      this.form.bisFixedCostsFwlx = obj.bisYmkdzFwlx
      this.form.bisFixedCostsZhid = that.zhid
      this.form.bisFixedCostsJzid = that.jzid
      this.form.bisFixedCostsZxks = that.zxks
    },
    handleClick(rowOjb, type) {
      this.$confirm(`确认退费?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        refundPay(rowOjb.payJsTranFlowNo, type).then(res => {
          this.$notify({
            title: res,
            type: 'warning',
            duration: 2500
          })
        }).catch(() => { })
      }).catch(() => {
      })
      console.log(rowOjb)
    }
  }
}
</script>

<style scoped>

</style>
